<?php
App::uses('AppModel', 'Model');
/**
 * Page Model
 *
 */
class Page extends AppModel {

	public $actsAs = array('Pagination');
/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'title';

/**
 * Validation rules
 *
 * @var array
 */
	public $validate = array(
		'sign' => array(
			'notEmpty' => array(
				'rule' => array('notEmpty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'title' => array(
			'notEmpty' => array(
				'rule' => array('notEmpty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'sort' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'enable' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	
/**
	 * 显示字段
	 * @author lj@gootop.net
	 * @Date 2014-1-2
	 * @param
	 * @return
	 */
	function pageParam($action){
		return array(
				"colNames"=>array(
						'ID','名称','标题','状态','修改时间','操作'
				),
				"colModel"=>array(
						array("name"=>'Page.id',"width"=>'50',"sortable"=>true,"align"=>"center"),
						array("name"=>'Page.sign',"width"=>'100',"sortable"=>true,"align"=>"left"),
						array("name"=>'Page.title',"width"=>"200","sortable"=>true,"align"=>"left"),
						array("name"=>'Page.enable',"width"=>"50","sortable"=>true,"align"=>"center"),
						array("name"=>'Page.modified',"width"=>"100","sortable"=>true,"align"=>"center"),
						array("name"=>'act',"width"=>"50","sortable"=>false,"align"=>"center")
				),
				"action"=>$action,
				'sortname'=>'id',
				'sortorder'=>'DESC'
		);
	}
	
	/**
	 * 显示数据
	 * @author lj@gootop.net
	 * @Date 2014-1-2
	 * @param
	 * @return
	 */
	function jsonData($res){
		$rowN = array();
		$i=0;
		foreach($res['rows'] as $k => $value){
			$rowN[$i]['id'] = $value['Page']['id'];
			$enable = ($value['Page']['enable'] == '1')?'<font color="green">已启用</font>':'<font color="red">未启用</font>';
			$rowN[$i++]['cell'] = array(
					$value['Page']['id'],
					$value['Page']['sign'],
					$value['Page']['title'],
					$enable,
					$value['Page']['modified'],
					''
			);
		}
		$res['rows'] = $rowN;
		return json_encode($res);
	}
}
